package com.danco.planner.viewcontrollers;

import com.danco.planner.services.StudentsListService;
import com.danco.planner.supportclasses.enumeration.IEventType;
import com.danco.planner.supportclasses.enumeration.PlannerEventType;
import com.danco.planner.view.builders.ConsoleViewsBuilder;
import com.danco.planner.view.core.AbstractButton;
import com.danco.planner.view.core.View;

public class StudentsVC extends AbstractPlannerVC {

	public StudentsVC() {
		super();
		// TODO Auto-generated constructor stub
	}
	public StudentsVC(View view) {
		super(view);
		// TODO Auto-generated constructor stub
	}
	public StudentsVC(View view, String title) {
		super(view, title);
		// TODO Auto-generated constructor stub
	}

	@Override
	protected void initAllOtherSubviews() {
		
		AbstractButton sortByNameBtn = new ConsoleViewsBuilder().buildButton("Sort by name", "sbName", PlannerEventType.sortByName);
		sortByNameBtn.addListener(this);
		baseView.addSubview(sortByNameBtn);
	}
	@Override
	protected String getMainContent() {
		return StudentsListService.getStudentsListDescription();
	}
	
	@Override
	public void handleAction(Object arg0, IEventType arg1) {
		
		super.handleAction(arg0, arg1);
		
		if (arg1 == PlannerEventType.sortByName) {
			sortByName();
		}
	}
	
	private void sortByName() {
		this.contentLabel.setText(StudentsListService.getStudentsListDescriptionSortedByName());
	}
}
